package com.itspeedster.betterforeyes;

import java.awt.AWTException;
import java.awt.SystemTray;
import java.awt.TrayIcon;

import javax.swing.JOptionPane;

public class AppTrayIcon extends TrayIcon{

	public AppTrayIcon(){
		super(AppRessources.getAppIcon(), "Better for eyes");
		setImageAutoSize(true);
		setPopupMenu(new AppPopupMenu());
	}
	
	public boolean addToSystemTray(){
		if (!SystemTray.isSupported()){
			JOptionPane.showMessageDialog(null, 
					"Ứng dụng không được hỗ trợ để chạy System Tray", 
					"Gặp vấn đề", 
					JOptionPane.ERROR_MESSAGE);
			return false;
		}
		
		final SystemTray systemTray = SystemTray.getSystemTray();
		try {
            systemTray.add(this);
        } catch (AWTException e) {
            return false;
        }
		return true;
	}
}
